var sellerCode="";
$(document).ready(function() {
	//top.UppTabs.operator = top.getCurrentTagTitle();// 设置用户tab的标题值

	
	$( "#sellers" ).autocomplete({
		source: function( request, response ) {
	        $.ajax({
	          url: contextPath + '/iccard/report/getPackages',
	          dataType: "json",
	          data: {
	            maxRows: 10,
	            keyword: request.term
	          },
	          success: function( data ) {
	        	sellerCode="";
	            response( $.map( data, function( item ) {
	              return {
	                label: item.value+','+item.label,
	                value: item.label
	              };
	            }));
	          }
	        });
	      },
	      minLength: 2,
	      select: function( event, ui ) {
		        sellerCode=ui.item.label;
	      },
	      open: function() {
	        $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
	      },
	      close: function() {
	        $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
	      }
	    });
	    
});

function doSearch(){
	$("#data_list").datagrid({
		onLoadError : function() {
			uppAjaxError(data);
		},
		onLoadSuccess:function(data){
			$("#export_link").attr('href',contextPath+'/iccard/report/temp/'+data.fileName);
		},
		queryParams : {
			packageId : sellerCode,
			status:$("#statusSelector").val()
		},
		frozenColumns : [ [ {
			field : 'comboCardName',
			title : '套餐名称',
			width : 80
		}, ] ],
		columns : [ [ {
			field : 'comboCardEarningsSumId',
			title : '',
			hidden : true
		}, {
			field : 'begintime',
			title : '套餐开始时间',
			formatter : function(value, row, index) {
				var d =new Date(Number(value));
				return d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
			}
		}, {
			field : 'endtime',
			title : '套餐结束时间',
			formatter : function(value, row, index) {
				var d =new Date(Number(value));
				return d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
			}
		}, {
			field : 'comboCardStatus',
			title : '套餐状态',
			formatter : function(value, row, index) {
				return value == 0 ? "已结束" : "未结束";
			}
		}, {
			field : 'comboCardExpectedEarnings',
			title : '当前预期收益累积'
		}, {
			field : 'comboCardId',
			title : '操作',
			formatter : function(value, row, index) {
				return "<input type=\"button\" value=\"查看明细\" onclick=\"showDetail("+row.comboCardEarningsSumId+",'"+row.comboCardName+"');\" />";
			}
		} ] ],
		autoRowHeight : true,
		fitColumns : true,
		pagination : true,
		nowrap : false,
		singleSelect : true,
		rownumbers : true
	});
}

function showDetail(id,name){
	var _title = "套餐卡收益额明细";
	var _href = contextPath
			+ "/iccard/report/bznis/package/detail.jsp?cardId=" + id
			+ "&cardName=" + name;
	parent.addTab(_title,_href);
}
